package com.itheima.server.controller;

import com.itheima.server.service.SettingsService;
import com.itheima.vo.PageResult;
import com.itheima.vo.SettingsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/users")
public class SettingsController {


    @Resource
    private SettingsService settingsService;

    /**
     * 查询设置
     *
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity<SettingsVo> settings() {
        SettingsVo settingsVo = settingsService.settings();
        return ResponseEntity.ok(settingsVo);
    }

    /**
     * 设置陌生人问题
     * @param map
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity<String> questions(@RequestBody Map map) {
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok("OK");
    }

    /**
     * 修改那啥
     * @param map
     * @return
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity<String> notifications(@RequestBody Map map){
        settingsService.notifications(map);
        return ResponseEntity.ok("OK");
    }

    /**
     * 查询黑名单列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/blacklist")
    public ResponseEntity<PageResult> blacklist(@RequestParam(defaultValue = "1") int page,
                                                @RequestParam(defaultValue = "10") int size){
        PageResult pageInfo = settingsService.page(page,size);
        return ResponseEntity.ok(pageInfo);
    }

    /**
     * 移除黑名单
     * @param uid
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity<String> deleteBlackList(@PathVariable Long uid){
        settingsService.deleteBlackList(uid);
        return ResponseEntity.ok("OK");
    }



}
